package com.forward.uploadapp.entity;

import android.content.Context;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ljh on 17-12-15.
 */

public class JsonAllParse implements Serializable {
    private String result;
    private String message;
    private List<AppInfo> infos;

    public JsonAllParse() {
    }

    public JsonAllParse(List<AppInfo> appInfos) {
        infos = appInfos;
    }

    public JsonAllParse(JSONObject obj) throws JSONException {
        result = obj.getString("result");
        message = obj.getString("message");
        infos = new ArrayList<>();
        JSONArray arr = obj.getJSONArray("data");
        for (int i = 0; i < arr.length(); i++) {
            infos.add(new AppInfo(arr.getJSONObject(i)));
        }
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<AppInfo> getInfos() {
        return infos;
    }

    public void setInfos(List<AppInfo> infos) {
        this.infos = infos;
    }

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("{\"result\":\"").append(200).append("\",");
        buffer.append("\"message\":\"").append("ok").append("\",");
        buffer.append("\"data\":").append("[\n");
        if (infos.size() > 0) {
            for (int i = 0; i < infos.size(); i++) {
                buffer.append(infos.get(i).toString());
                if (i != infos.size() - 1) {
                    buffer.append(",");
                }
                buffer.append("\n\n");
            }
        }
        buffer.append("]}");
        return buffer.toString();
    }
}